<template>
    <div class="cmdcfg">
        <el-row>
            <div>
                <exSelect v-model="key" label="系统键" @change="onChange" :dictList="typeList" size="mini" elstyle="width:100px;min-width:100px"></exSelect>
                <!-- {{devInfo?devInfo.curImg:"null"}} -->
                
                <el-tooltip class="item" effect="light" placement="bottom" v-show="desc" >
                    <div slot="content"> 
                        <el-row style="word-break: break-all;display:inline-block;max-width:500px;">
                            {{desc}}
                        </el-row>
                    </div>
                    <el-link type="primary">
                        {{desc.substring(0,10)}}..
                    </el-link>
                </el-tooltip>
            </div>

        </el-row>
    </div>
</template>


<script>

export default {
    components:{
    },
    props: {
        cmdInfo: { type: Object, default: {} },
        devInfo:{ type: Object, default: {} },
        cmdIdx : {},
    },
    data() {
        return {
            typeList:[
                {name:"HOME",value:3,isKey:true},
                {name:"BACK",value:4,isKey:true},
                {name:"更新画面",value:"Screen","desc":"截屏"},
                {name:"更新当前应用",value:"CurApp"}

            ],
            key : this.cmdInfo.key || 4,
            isWaiting : false,
            desc : "",
        };
    },
    inject: ['doDevCmd','doNextCmd','addCmd',"doDevKeyEvent","getDevPic","getCurApp"],
    watch:{
        "devInfo.curAppRnd"(){
            this.$emit("stopRun")
            // alert(this.devInfo.curApp);
            if(this.isWaiting){
                this.desc = this.devInfo.curApp;
                this.isWaiting = false;
                this.doNextCmd();
            }
        },
        "devInfo.curImg"(){
            // alert(this.devInfo.curImg);
            this.$emit("stopRun")
            if(this.isWaiting){
                this.isWaiting = false;
                this.doNextCmd();
            }
        }
    },
    computed:{
        selType(){
            var type = {};
            type = this.typeList.find((item)=>{
                return item.value==this.key
            })
            type = type || {};
            return type;
        }
    },

    mounted() {
    },

    methods: {
        onChange(){
            this.desc="";
        },
        setByDevInfo(){
        },
        preView(){
        },
        saveCmd(){
            this.cmdInfo.key = this.key;
        },
        initCmd(){
            this.isWaiting = false;
            this.desc = "";
        },
        preCheck(){
            if(!this.key){
                this.$message.error("请选择按键")
                return false;
            }
            return true;
        },
        runCmd(isOnce){
            if(!this.preCheck()){
                this.$emit("stopRun")
                return;
            }
            this.desc = "";
            this.isWaiting = false;
            if(this.selType.isKey){
                this.doDevKeyEvent(this.key);
                this.doActionScreen();
            }else{
                this.doAction(isOnce);
            }

        },
        stopCmd(){
            this.isWaiting = false;
            this.$emit("stopRun")
        },
        doAction(isOnce){
            if(this["doAction"+this.selType.value]){
                this["doAction"+this.selType.value].call(this);
            }else{
                if(isOnce!==true) this.doNextCmd();
            }
        },
        doActionScreen(){
            this.isWaiting = true;
            this.getDevPic()
        },
        doActionCurApp(){
            this.isWaiting = true;
            this.getCurApp()
        },
        
    }
}
</script>

<style lang="less" scoped>
    .cmdcfg{
        display: inline-block;
    }
</style>
